package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.Cheyou;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.mapper.CheyouMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CheyouhuiMapper;
import com.ruoyi.system.domain.Cheyouhui;
import com.ruoyi.system.service.ICheyouhuiService;
import com.ruoyi.common.support.Convert;

/**
 * 车友会 服务层实现
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Service
public class CheyouhuiServiceImpl implements ICheyouhuiService 
{
	@Autowired
	private CheyouhuiMapper cheyouhuiMapper;
	@Autowired
	private CheyouMapper cheyouMapper;
	/**
     * 查询车友会信息
     * 
     * @param cheyouhuiId 车友会ID
     * @return 车友会信息
     */
    @Override
	public Cheyouhui selectCheyouhuiById(Integer cheyouhuiId)
	{
	    return cheyouhuiMapper.selectCheyouhuiById(cheyouhuiId);
	}
	
	/**
     * 查询车友会列表
     * 
     * @param cheyouhui 车友会信息
     * @return 车友会集合
     */
	@Override
	public List<Cheyouhui> selectCheyouhuiList(Cheyouhui cheyouhui)
	{
	    return cheyouhuiMapper.selectCheyouhuiList(cheyouhui);
	}
	
    /**
     * 新增车友会
     * 
     * @param cheyouhui 车友会信息
     * @return 结果
     */
	@Override
	public int insertCheyouhui(Cheyouhui cheyouhui)
	{
	    return cheyouhuiMapper.insertCheyouhui(cheyouhui);
	}
	
	/**
     * 修改车友会
     * 
     * @param cheyouhui 车友会信息
     * @return 结果
     */
	@Override
	public int updateCheyouhui(Cheyouhui cheyouhui)
	{
	    return cheyouhuiMapper.updateCheyouhui(cheyouhui);
	}

	/**
     * 删除车友会对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteCheyouhuiByIds(String ids)
	{
		return cheyouhuiMapper.deleteCheyouhuiByIds(Convert.toStrArray(ids));
	}

	/**
	 * 修改车友会状态
	 * @param cheyouhui
	 * @return
	 */
	@Override
	public int changeStatus(Cheyouhui cheyouhui) {
		return cheyouhuiMapper.updateCheyouhui(cheyouhui);
	}

	/**
	 * 根据车友人员表中的车友会ID查询所有车友会
	 * @param cheyouId
	 * @return
	 */
	@Override
	public List<Cheyouhui> selectCheyouhuId(Integer cheyouId) {
		Cheyou cheyou = cheyouMapper.selectCheyouById(cheyouId);
		List<Cheyouhui> cheyouhuis = cheyouhuiMapper.selectCheyouhuiList(null);
		if(cheyou != null){
			for(Cheyouhui cheyouhui:cheyouhuis){
				if(cheyou.getCheyouhuiId()==cheyouhui.getCheyouhuiId()){
					cheyouhui.setFlag(true);
				}
			}
		}
		return cheyouhuis;
	}

}
